package com.haotunet.app.goldtreasure.utils;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;

import com.haotunet.app.goldtreasure.activity.BuyGoldActivity;
import com.haotunet.app.goldtreasure.activity.CurrentTransferActivity;
import com.haotunet.app.goldtreasure.activity.DepositGoldActivtity;
import com.haotunet.app.goldtreasure.activity.DiscountActivity;
import com.haotunet.app.goldtreasure.activity.DynamicDetailActivity;
import com.haotunet.app.goldtreasure.activity.FeedBackActivity;
import com.haotunet.app.goldtreasure.activity.FinanicalDetailActivity;
import com.haotunet.app.goldtreasure.activity.FindPwdActivity;
import com.haotunet.app.goldtreasure.activity.ForgetTradePwdAct;
import com.haotunet.app.goldtreasure.activity.GCoinDetailActivity;
import com.haotunet.app.goldtreasure.activity.GPriceTrendActivty;
import com.haotunet.app.goldtreasure.activity.GoldOrderActivity;
import com.haotunet.app.goldtreasure.activity.LoginActivity;
import com.haotunet.app.goldtreasure.activity.MainActivity;
import com.haotunet.app.goldtreasure.activity.MyBankCardActivity;
import com.haotunet.app.goldtreasure.activity.MyProfitActivity;
import com.haotunet.app.goldtreasure.activity.MyRegularGoldAct;
import com.haotunet.app.goldtreasure.activity.MyVaultActivity;
import com.haotunet.app.goldtreasure.activity.MyWalletActivity;
import com.haotunet.app.goldtreasure.activity.NewGuideLinesActivity;
import com.haotunet.app.goldtreasure.activity.NewUserBuyActivity;
import com.haotunet.app.goldtreasure.activity.OrderSuccessActivity;
import com.haotunet.app.goldtreasure.activity.PersonalInfoActivity;
import com.haotunet.app.goldtreasure.activity.PickGoldActivity;
import com.haotunet.app.goldtreasure.activity.PickGoldNextActivity;
import com.haotunet.app.goldtreasure.activity.RealNameAnthActivity;
import com.haotunet.app.goldtreasure.activity.RechargeFStebActivity;
import com.haotunet.app.goldtreasure.activity.RedPacketActivity;
import com.haotunet.app.goldtreasure.activity.RegisterActivity;
import com.haotunet.app.goldtreasure.activity.ResetPwdActivity;
import com.haotunet.app.goldtreasure.activity.SellGoldActivity;
import com.haotunet.app.goldtreasure.activity.ShopPositionActivity;
import com.haotunet.app.goldtreasure.activity.StoreDepositReserveAct;
import com.haotunet.app.goldtreasure.activity.StoreExchangeReserveAct;
import com.haotunet.app.goldtreasure.activity.StorePickReserveAct;
import com.haotunet.app.goldtreasure.activity.SupportBankActivity;
import com.haotunet.app.goldtreasure.activity.TransRecordActivity;
import com.haotunet.app.goldtreasure.activity.WeChatRegisterActivity;
import com.haotunet.app.goldtreasure.activity.WithdrawalsRecordAct;
import com.haotunet.app.goldtreasure.db.DBOpenHelper;
import com.haotunet.app.goldtreasure.fragment.BaseFragment;
import com.haotunet.app.goldtreasure.model.BuyConfirmModel;
import com.haotunet.app.goldtreasure.model.DepositOrder;
import com.haotunet.app.goldtreasure.model.OrderInfo;
import com.haotunet.app.goldtreasure.model.StoreInfo;
import com.haotunet.app.goldtreasure.views.MyAlertDialog;

public class ActivityUtils {
    public static void gotoLogin(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, LoginActivity.class);
        context.startActivity(intent);
    }

    public static void gotoBuyGold(Context context, int flag, String productName, String regularId, int productFlag, int productType) {
        Intent intent = new Intent();
        intent.setClass(context, BuyGoldActivity.class);
        intent.putExtra("flag", flag);
        intent.putExtra("productName", productName);
        intent.putExtra("regularId", regularId);
        intent.putExtra("productFlag", productFlag);
        intent.putExtra("productType", productType);
        context.startActivity(intent);
    }

    public static void gotoSellGold(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, SellGoldActivity.class);
        context.startActivity(intent);
    }

    public static void gotoResetPwd(Context context, int type) {
        Intent intent = new Intent();
        intent.setClass(context, ResetPwdActivity.class);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    public static void gotoForgetTradePwd(Context context, int source) {
        Intent intent = new Intent();
        intent.setClass(context, ForgetTradePwdAct.class);
        intent.putExtra("source", source);
        context.startActivity(intent);
    }

    public static void gotoRecharge(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, RechargeFStebActivity.class);
        context.startActivity(intent);
    }

    public static void gotoDepositGold(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, DepositGoldActivtity.class);
        context.startActivity(intent);
    }

    public static void skipToMain(Context context, String type) {
        Intent intent = new Intent();
        intent.setClass(context, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    public static void gotoPickGoldNext(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, PickGoldNextActivity.class);
        context.startActivity(intent);
    }

    public static void gotoPickGold(Context context, String type) {
        Intent intent = new Intent();
        intent.setClass(context, PickGoldActivity.class);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    public static void gotoTransRecord(Context context, String type) {
        Intent intent = new Intent();
        intent.setClass(context, TransRecordActivity.class);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    public static void gotoGCoinDetail(Context context, String coinNum) {
        Intent intent = new Intent();
        intent.setClass(context, GCoinDetailActivity.class);
        intent.putExtra("coinNum", coinNum);
        context.startActivity(intent);
    }

    public static void gotoRedPacket(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, RedPacketActivity.class);
        context.startActivity(intent);
    }

    public static void gotoSupportBank(Activity activity, int code) {
        Intent intent = new Intent();
        intent.setClass(activity, SupportBankActivity.class);
        activity.startActivityForResult(intent, code);
    }

    public static void gotoDiscount(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, DiscountActivity.class);
        context.startActivity(intent);
    }

    public static void gotoMyWallet(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, MyWalletActivity.class);
        context.startActivity(intent);
    }

    public static void gotoMyVault(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, MyVaultActivity.class);
        context.startActivity(intent);
    }

    public static void gotoPersonalInfo(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, PersonalInfoActivity.class);
        context.startActivity(intent);
    }

    public static void gotoOrderSuccess(Context context, DepositOrder order) {
        Intent intent = new Intent();
        intent.setClass(context, OrderSuccessActivity.class);
        Bundle bd = new Bundle();
        bd.putSerializable("depositorder", order);
        intent.putExtras(bd);
        context.startActivity(intent);
    }

    public static void gotoNewUserBuy(Context context, String payType, OrderInfo info) {
        Intent intent = new Intent();
        intent.setClass(context, NewUserBuyActivity.class);
        Bundle bd = new Bundle();
        bd.putSerializable("orderInfo", info);
        intent.putExtra("payType", payType);
        intent.putExtras(bd);
        context.startActivity(intent);
    }

    public static void gotoFindPwd(Context context, String describtion, String btnText, int type, String wechatCode) {
        Intent intent = new Intent();
        intent.setClass(context, FindPwdActivity.class);
        intent.putExtra("describtion", describtion);
        intent.putExtra("btnText", btnText);
        intent.putExtra("type", type);
        intent.putExtra("wechatCode", wechatCode);
        context.startActivity(intent);
    }

    public static void gotoRegister(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, RegisterActivity.class);
        context.startActivity(intent);
    }

    public static void gotoStoreDeposit(Context context, StoreInfo info, String shopId) {
        Intent intent = new Intent();
        intent.setClass(context, StoreDepositReserveAct.class);
        Bundle bd = new Bundle();
        bd.putSerializable("storeDetailInfo", info);
        intent.putExtras(bd);
        intent.putExtra("shopId", shopId);
        context.startActivity(intent);
    }

    public static void gotoStorePick(Context context, StoreInfo info, String shopId, int gram20, int gram50,
                                     int gram100, int gram200, int gram500, int gram1000) {
        Intent intent = new Intent();
        intent.setClass(context, StorePickReserveAct.class);
        Bundle bd = new Bundle();
        bd.putSerializable("storeDetailInfo", info);
        intent.putExtras(bd);
        intent.putExtra("shopId", shopId);
        intent.putExtra("gram20", gram20);
        intent.putExtra("gram50", gram50);
        intent.putExtra("gram100", gram100);
        intent.putExtra("gram200", gram200);
        intent.putExtra("gram500", gram500);
        intent.putExtra("gram1000", gram1000);
        context.startActivity(intent);
    }

    public static void gotoStoreExchange(Context context, StoreInfo info, String shopId) {
        Intent intent = new Intent();
        intent.setClass(context, StoreExchangeReserveAct.class);
        Bundle bd = new Bundle();
        bd.putSerializable("storeDetailInfo", info);
        intent.putExtras(bd);
        intent.putExtra("shopId", shopId);
        context.startActivity(intent);
    }

    public static void gotoCurrentTransfer(Context context, String regularId, String productName) {
        Intent intent = new Intent();
        intent.setClass(context, CurrentTransferActivity.class);
        intent.putExtra("regularId", regularId);
        intent.putExtra("productName", productName);
        context.startActivity(intent);
    }

    public static void gotoDynamicDetail(Context context, String url, int type) {
        Intent intent = new Intent();
        intent.setClass(context, DynamicDetailActivity.class);
        intent.putExtra("activityUrl", url);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }
    public static void gotoFeedBack(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, FeedBackActivity.class);
        context.startActivity(intent);
    }

    public static void gotoMyProfit(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, MyProfitActivity.class);
        context.startActivity(intent);
    }

    public static void gotoFinanicalDetail(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, FinanicalDetailActivity.class);
        context.startActivity(intent);
    }

    public static void gotoMain(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, MainActivity.class);
        context.startActivity(intent);
    }

    public static void gotoGoldOrder(Context context, BuyConfirmModel model, String buyType, String productId, int flag) {
        Intent intent = new Intent();
        intent.setClass(context, GoldOrderActivity.class);
        Bundle bd = new Bundle();
        bd.putSerializable("buyConfirmModel", model);
        bd.putString("buyType", buyType);
        bd.putString("productId", productId);
        bd.putInt("flag", flag);
        intent.putExtras(bd);
        context.startActivity(intent);
    }

    public static void gotoMyBankCard(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, MyBankCardActivity.class);
        context.startActivity(intent);
    }

    public static void gotoRealNameAuth(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, RealNameAnthActivity.class);
        context.startActivity(intent);
    }

    public static void gotoWithDrawsRecord(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, WithdrawalsRecordAct.class);
        context.startActivity(intent);
    }

    public static void gotoShopPosition(Context context, String shopAddress, double latitude, double longitude,
                                        String shopName) {
        Intent intent = new Intent();
        intent.setClass(context, ShopPositionActivity.class);
        intent.putExtra("shopAddress", shopAddress);
        intent.putExtra("longitude", longitude);
        intent.putExtra("latitude", latitude);
        intent.putExtra("shopName", shopName);
        context.startActivity(intent);
    }

    public static void gotoNewGuideLines(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, NewGuideLinesActivity.class);
        context.startActivity(intent);
    }

    public static void gotoGPriceTrend(Context context, String url) {
        Intent intent = new Intent();
        intent.setClass(context, GPriceTrendActivty.class);
        intent.putExtra("url", url);
        context.startActivity(intent);
    }

    public static void gotoMyRegularProduct(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, MyRegularGoldAct.class);
        context.startActivity(intent);
    }

    public static void gotoWechatRegister(Context context, String phone, String wechatCode) {
        Intent intent = new Intent();
        intent.setClass(context, WeChatRegisterActivity.class);
        intent.putExtra("phone", phone);
        intent.putExtra("wechatCode", wechatCode);
        context.startActivity(intent);
    }

    public static void forceQuit(final Context context, String text) {
        ShareStore shareStore = new ShareStore(context);
        DBOpenHelper helper = new DBOpenHelper(context);
        shareStore.putBoolean(Strs.IS_LOGIN, false);
        shareStore.putString(Strs.TOKEN, "");
        shareStore.commit();
        helper.deleteValue(helper.getMobile());
        new MyAlertDialog(context).builder().setMsg(text).setCancelable(false)
                .setPositiveButton("确定", true,new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        intent.setClass(context, MainActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        intent.putExtra("type", "forceQuit");
                        context.startActivity(intent);
                    }
                }).show();
    }

    public static void backgroundAlpha(Activity context, float bgAlpha) {
        WindowManager.LayoutParams lp = context.getWindow().getAttributes();
        lp.alpha = bgAlpha;
        context.getWindow().setAttributes(lp);
        context.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    /**
     * 获取当前运行的Activity名称
     */
    public static String getRunningActivityName(Context context) {
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        String activityName = manager.getRunningTasks(1).get(0).topActivity.getClassName();
        String name = activityName.substring(activityName.lastIndexOf(".") + 1, activityName.length());
        return name;
    }

    /**
     * 获取当前显示的Fragment名称
     */
    public static String getCurrentFragmentName(BaseFragment fragment) {
        String fragName = fragment.getClass().toString();
        fragName = fragName.substring(fragName.lastIndexOf(".") + 1, fragName.length());
        return fragName;
    }
}
